﻿using System.Web.Http;
using MyWebApp.Data;

namespace MyWebApp.Controllers
{
    public class BikesController : ApiController
    {
        private readonly IBikesSearchService _bikesSearchService;

        public BikesController(IBikesSearchService bikesSearchService)
        {
            _bikesSearchService = bikesSearchService;
        }

        public SearchBikesResult Get(string name, string category, string state, int pageNumber)
        {
            //TODO: ADD TERMS OF USE

            int numberOfItemsFound;
            var bikes = _bikesSearchService.GetBikes(name, Mapper.MapCategory(category), Mapper.MapSate(state), pageNumber, out numberOfItemsFound);

            return new SearchBikesResult()
            {
                NumberOfItemsFound = numberOfItemsFound,
                Bikes = bikes
            };
        }
    }
}
